package com.leo.base.initialize;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

/**
 * @ClassName HelloSpringApplicationRunListener
 * @Description
 * @Author wangss
 * @date 2020.09.20 15:37
 * @Version 1.0
 */
@Slf4j
public class HelloSpringApplicationRunListener implements SpringApplicationRunListener {

    /**
     * 必须有的构造器
     *
     * @param application
     * @param args
     */
    public HelloSpringApplicationRunListener(SpringApplication application, String[] args) {
    }

    @Override
    public void starting() {
        // 这个运行的太早了，早到日志组件都没有加载
        log.info("运行 SpringApplicationRunListener:SpringApplicationRunListener...starting...");
        System.out.println("运行 SpringApplicationRunListener:SpringApplicationRunListener...starting...");
    }

    @Override
    public void environmentPrepared(ConfigurableEnvironment environment) {
        Object o = environment.getSystemProperties().get("os.name");
        log.info("获取系统环境：SpringApplicationRunListener:SpringApplicationRunListener...environmentPrepared...{}", o);

    }

    @Override
    public void contextPrepared(ConfigurableApplicationContext context) {
        log.info("运行 SpringApplicationRunListener:SpringApplicationRunListener...contextPrepared...");
    }

    @Override
    public void contextLoaded(ConfigurableApplicationContext context) {
        log.info("运行 SpringApplicationRunListener:SpringApplicationRunListener...contextLoaded...");
    }

    @Override
    public void started(ConfigurableApplicationContext context) {
        log.info("运行 SpringApplicationRunListener:SpringApplicationRunListener...started...");
    }

    @Override
    public void running(ConfigurableApplicationContext context) {
        log.info("运行 SpringApplicationRunListener:SpringApplicationRunListener...running...");
    }

    @Override
    public void failed(ConfigurableApplicationContext context, Throwable exception) {
        log.info("运行 SpringApplicationRunListener:SpringApplicationRunListener...failed...");
    }
}
